package ruk.applications.copyhelper.test;

import com.thoughtworks.selenium.SeleneseTestCase;
import org.openqa.selenium.server.SeleniumServer;

public class BaseTestCase extends SeleneseTestCase {
    private static SeleniumServer seleniumServer;
    private static final String SPEED = "100";
    protected static final String BASE_APP_URL = "http://localhost:9797/";
    protected static final String DATA_LIST_BOX_LOCATOR = "id=dataListBox";
    protected static final String SELECTED_DATA_TEXT_AREA_LOCATOR = "id=selectedDataTextArea";
    protected static final String COPY_BUTTON_LOCATOR = "id=copyButton";

    public void start() throws Exception {
        if (seleniumServer == null) {
            seleniumServer = new SeleniumServer(SeleniumServer.DEFAULT_PORT);
            seleniumServer.start();
        }
    }

    public BaseTestCase() {
        try {
            start();
        } catch (Exception e) {
            System.out.println("Unable to start the selenium server.");
            e.printStackTrace();
        }
    }

    public void setUp(String url, String browserString) throws Exception {
        super.setUp(url, browserString);
        selenium.setSpeed(SPEED);
    }

    protected void assertElementPresent(String locator) {
        assertTrue(selenium.isElementPresent(locator));
    }
}
